from typing import List
from collections import deque
class Solution:
    def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
        in_degrees = [0 for _ in range(numCourses)]
        adjancy = [[] for _ in range(numCourses)]
        queue = deque()
        
        for item in prerequisites:
            cur, pre = item
            in_degrees[cur] += 1
            adjancy[pre].append(cur)
        for i, v in enumerate(in_degrees):
            if in_degrees[i] == 0:
                queue.append(i)
        while queue:
            node = queue.popleft()
            numCourses -= 1
            for i in adjancy[node]:
                in_degrees[i] -= 1
                if in_degrees[i] == 0:
                    queue.append(i)
        return numCourses == 0
